<template>
	<view class="login_container">
		<uni-icons type="contact-filled" size="80" color="#AFAFAF"></uni-icons>
    <button type="primary" class="login_btn" @click="getUserProfile">一键登录</button>
    <text>登陆后尽享更多权益</text>
	</view>
</template>

<script>
  import{mapMutations,mapState} from 'vuex'
	export default {
		data() {
			return {
				
			};
		},
    computed:{
      ...mapState('m_user',['jumpType'])
    },
 methods:{
   ...mapMutations('m_user',['updataUserData','updataToken','updataType']) ,
   getUserProfile(e){
     // console.log('eeee',e)
     let userMsg={}
     let that=this
    wx.getUserProfile({
       desc: '用于登录功能', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
       success:async (res) => {
         console.log('res.rawData',res.rawData)
         // const [err,suc]=await uni.login().catch(err=>err) //获取code
         
         wx.login({
          async success(codeResult) {
       const query={
         code:codeResult.code,
         encryptedData:res.encryptedData,
         iv:res.iv,
         rawData:res.rawData,
         signature:res.signature
       }
       console.log(query)
       if(codeResult.errMsg!=='login:ok')return uni.$showMsg('登陆失败！')
         if(!res.errMsg=="getUserProfile:ok")return uni.$showMsg('用户取消了登录！')
         
         that.updataUserData(query)
       const {data:res2} = await uni.$http.post('/api/public/v1/users/wxlogin',query)
           console.log(333333333333333,res2)
       // if(res2.meta.status!=200)return uni.$showMsg('登录失败！')
             
       that.updataToken(123)
           }
         })
         
         if(this.jumpType){
           uni[this.jumpType.openType]({
             url:this.jumpType.from
           })
           this.updataType({})
         }
       },
     })
   
   }
 }
	}
</script>

<style lang="scss">
.login_container{
  position: relative;
  background-color: #F8F8F8;
  height: 750rpx;
  display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
  .login_btn{
    width: 90%;
    background-color: #c00000!important;
    border-radius: 100px;
    margin-top: 20px;
  }
  text{
    color: gray;
    font-size: 10px;
    padding: 10px 0;
  }
  &::after{
    display: block;
    content: '';
    width: 100%;
    border-radius: 100%;
    height: 40px;
    background-color: white;
    position: absolute;
    bottom: 0;
    left: 0;
    transform: translateY(50%);
  }
}
</style>
